from odoo import fields, models


class EstatePropertyType(models.Model):

    _name = "estate.property.type"
    _description = "Estate property type"
    _order = "sequence, name"

    name = fields.Char(string="Name", required=True)

    # One property type can be applied to many properties
    property_ids = fields.One2many("estate.property", "property_type_id")

    sequence = fields.Integer("Sequence", default=1)

    offer_ids = fields.One2many("estate.property.offer", "property_type_id")

    offer_count = fields.Integer(compute="_compute_offer_count")

    # Counts the number of offers for a given property type
    @api.depends("offer_ids")
    def _compute_offer_count(self):
        for record in self:
            record.offer_count = len(record.offer_ids)
